const
	gulp = require("gulp"),
	babel = require("gulp-babel"),
	uglify = require("gulp-uglify"),
	htmlmin = require("gulp-htmlmin"),
	sass = require("gulp-sass"),
	connect = require("gulp-connect");

gulp.task("js", ()=>{
	gulp.src("src/js/**/*.js")
			.pipe(babel({
	            presets: ['env']
	        }))
			.pipe(uglify())
			.pipe(gulp.dest("dist/js"))
			.pipe(connect.reload());
});

gulp.task("sass", ()=>{
	gulp.src("src/sass/**/*.scss")
			.pipe(sass({outputStyle: "compressed"}))
			.pipe(gulp.dest("dist/css"))
			.pipe(connect.reload());
});

gulp.task("html", ()=>{
	gulp.src("src/**/*.html")
			.pipe(htmlmin({ collapseWhitespace: true, minifyJS: true }))
			.pipe(gulp.dest("dist/"))
			.pipe(connect.reload());
});

gulp.task("copy-images", ()=>{
	gulp.src("src/img/**/*.*")
		.pipe(gulp.dest("dist/img"));
});
gulp.task("copy-lib", ()=>{
	gulp.src("src/lib/**/*.*")
		.pipe(gulp.dest("dist/lib"));
});
gulp.task("copy-css", ()=>{
	gulp.src("src/css/**/*.*")
		.pipe(gulp.dest("dist/css"));
});
gulp.task("copy", ["copy-images", "copy-lib", "copy-css"]);

gulp.task('server', function() {
	connect.server({
		root: "dist",
		port: 8080,
		livereload: true
	});
});

gulp.task("watch", ()=>{

	gulp.watch("src/sass/**/*.scss", ["sass"]);

	gulp.watch("src/**/*.html", ["html"]);

	gulp.watch("src/js/**/*.js", ["js"]);
});

gulp.task("default", ["sass", "js", "html", "copy", "server", "watch"]);
